import time

from Base.Base import Base
from selenium.webdriver.common.by import By

# 页面类
class Page2(Base):
    # 1.点击请登录
    login_loc=(By.XPATH,'/html/body/div[1]/div/div[2]/ul/li[1]/a')
    def login(self):
        self.click(self.login_loc)
    # 断言1 会员登录
    dy1_loc=(By.XPATH,'/html/body/div[4]/div/div[1]/div[1]/span[1]')
    def dy1(self):
        return self.text(self.dy1_loc)
    # 2.输入用户名
    user_loc=(By.NAME,'username')
    def user(self):
        self.send_keys(self.user_loc,'13811033962')
    # 3.输入密码
    pwd_loc=(By.NAME,'password')
    def pwd(self):
        self.send_keys(self.pwd_loc,'123456')
    # 4.点击登录按钮
    login1_loc=(By.CSS_SELECTOR,'.finish-btn')
    def login1(self):
        self.click(self.login1_loc)
    # 断言2 登录成功
    dy2_loc=(By.XPATH,'/html/body/div[5]/div[2]/div[1]/div[2]/div[2]/ul/li[1]')
    def dy2(self):
        return self.text(self.dy2_loc)
    # 5.点击首页
    home_loc=(By.XPATH,'/html/body/div[3]/div[2]/ul/li[1]/a')
    def home(self):
        self.click(self.home_loc)
    # 6.搜索输入并回车
    search_loc=(By.XPATH,'//input[@class="search-input" and @name="keywords"]')
    def search(self):
        self.send_keys(self.search_loc,'茅台')
        self.Enter(self.search_loc)
    # 7.点击商品进入商品详情页
    goods_loc=(By.XPATH,'/html/body/div[5]/div[2]/div[2]/div[1]/ul/li[1]/div[1]/span/a/img')
    def goods(self):
        self.click(self.goods_loc)
    # 断言3 茅台two
    dy3_loc=(By.XPATH,'/html/body/div[5]/div/div[2]/form/div/div[1]/span')
    def dy3(self):
        return self.text(self.dy3_loc)


    def luoji_a3mall_03_login_search(self):
        self.open_url('http://10.59.9.12:7001/')
        # 1.点击请登录
        self.login()
        # 断言1 会员登录
        print(self.dy1())
        assert "会员登录" == self.dy1()
        # 2.输入用户名
        self.user()
        # 3.输入密码
        self.pwd()
        # 强制等待输入验证码
        time.sleep(5)
        # 4.点击登录按钮
        self.login1()
        # 强制等待查看效果
        time.sleep(5)
        # 断言2 登录成功
        print(self.dy2())
        assert "您好，13811033962 欢迎回来！" in self.dy2()
        # 5.点击首页
        self.home()
        # 6.搜索输入并回车
        self.search()
        # 7.点击商品进入商品详情页
        self.goods()
        # 断言3 茅台two
        print(self.dy3())
        assert "茅台two" == self.dy3()